package com.dc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dc.common.ResponseResultVO;
import com.dc.entity.MapManagement;
import com.dc.entity.ro.MapManagementRO;
import com.dc.mapper.MapManagementMapper;
import com.dc.service.MapManagementService;
import com.dc.util.SnowflakeIdWorker;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import static com.dc.common.ResponseResultVO.checkParameterIsNotNull;

@Service
public class MapManagementServiceImpl extends ServiceImpl<MapManagementMapper, MapManagement> implements MapManagementService {

    @Resource
    private MapManagementMapper mapManagementMapper;


    @Override
    public ResponseResultVO insertMapManagement(MapManagementRO ro) {
        MapManagement mapManagement = new MapManagement();
        BeanUtils.copyProperties(ro, mapManagement);
        mapManagement.setId(SnowflakeIdWorker.generateId());
        return ResponseResultVO.insertResult(mapManagementMapper.insert(mapManagement));
    }

    @Override
    public ResponseResultVO updateMapManagement(MapManagementRO ro) {
        checkParameterIsNotNull(String.valueOf(ro.getId()), "id不能为空");
        MapManagement mapManagement = new MapManagement();
        BeanUtils.copyProperties(ro, mapManagement);
        return ResponseResultVO.updateResult(mapManagementMapper.updateById(mapManagement));
    }

    @Override
    public ResponseResultVO deleteMapManagement(String ids) {
        checkParameterIsNotNull(ids, "id不能为空");
        List<String> idList = Arrays.asList(ids.split(","));
        return ResponseResultVO.deleteResult(mapManagementMapper.deleteBatchIds(idList));
    }

    @Override
    public ResponseResultVO selectMapManagementList(MapManagementRO ro) {
        Page page = new Page<Map<String, Object>>(ro.getCurrentPage(), ro.getPageSize());
        return ResponseResultVO.resultList(mapManagementMapper.selectPage(page, new QueryWrapper()), ro);

    }
}
